<template>
    <div class="container">
        <div class="plan">
            <img src="~assets/img/home/login_img.png" alt="">
        </div>
        <article class="login">
            <h2 class="title">Login BCC Mandarin</h2>
            <div class="content">
                <button class="sign-btn" type="button" @click="ssoAuth()">Authentication login
                </button>
            </div>
        </article>
    </div>
</template>
<script>
    import utils from '~/plugins/utils';
    import axios from 'axios';
    import httpPath from "~/static/server.config.js";
    export default {
        asyncData({isServer, query, route, redirect}){
            return {
                op: query.op,
                cmd: query.cmd,
                uuid: query.uuid,
                username: query.username,
            }
        },
        data () {
            return {
            }
        },
        head: {
            script: [{src: "http://127.0.0.5/js/bcc_ssoauth.js"}]
        },
        methods: {
            async ssoAuth(){
                try {
                    let res = await axios.post(this.httpPath.replace("/proxy", "") + "/api/ssoauth",{data:{op:this.op,cmd:this.cmd,uuid: this.uuid, username: this.username}});
                    let status_code = +res.data.status_code;
                    if (status_code==20002) {
                        this.$_success("Re registration and binding");
                        this.$router.push({name:'home-ssobind',query:{cmd:this.cmd,uuid:this.uuid,username:this.username}});
                    } else if (status_code==20003) {
                        this.$_success("Users are not logged in. Please login first!");
                        this.$router.push('/');
                    } else if(status_code==200){
                        this.$_success("Authentication success");
                        let FORWARD_PATH = "/";
                        //如果已激活
                        setTimeout(() => {
                            const data = res.data.data;
                            switch (+data.customerType) {
                                case 1:
                                    FORWARD_PATH = "/learner";
                                    break;
                                case 2:
                                    FORWARD_PATH = "/educator";
                                    break;
                                default:
                                    break;
                            }
                            window.location.href = `http://${window.location.host}${FORWARD_PATH}`;
                        }, 1000);
                    }
                } catch (e) {
                    setTimeout(() => {
                        window.location.reload();
                    }, 1000);
                }
            }
        },
        created(){
            //let that = this;
            //const b = Base64();
            //console.log(b.decode('123dd'));
            console.log('op='+this.op+'&cmd='+this.cmd);
            
        },
        computed: {
        },
        components: {}
    }
</script>
<style lang="less">
    @import "~~assets/less/element/home";
</style>